// pages/zhuan_liao/zhuan_liao.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 2,
    value: "",
    scrollTop: "10000000",
    //聊天内容
    chatArr: [{
      id: 1,
      himg: "/hyb_yl/images/header_01.png",
      con: "发神经弗兰克萨解放路开始看就付款刘三姐抗裂砂浆啊客服就流口水发了啥浪费"
    },
    {
      id: 2,
      himg: "/hyb_yl/images/header_02.png",
      con: "发神经弗兰克萨解放路开始看就付款刘三姐抗裂砂浆啊客服就流口水发了啥浪费"
    },
    ],
    //隐藏展示
    hide: "",
    // 内容高度
    heights: "860",
    //底部
    //个人
    footerArr: [{
      img: "/hyb_yl/images/baogao_01.png",
      title: "体检报告",
      btn: "baoClick"
    },
    {
      img: "/hyb_yl/images/jiankangdangan_01.png",
      title: "健康档案",
      btn: "baoClick"
    },
    {
      img: "/hyb_yl/images/zhaopian_01.png",
      title: "发送照片",
      btn: "phoneClick"
    },
    ],
    //医生
    footerArr1: [{
      img: "/hyb_yl/images/chufang_01.png",
      title: "病情诊断",
      btn: "zhenClick"
    },
    {
      img: "/hyb_yl/images/zhaopian_01.png",
      title: "发送照片",
      btn: "phoneClick"
    },
    ],
    //遮罩层
    overflow: '',
    //跳转
    tiao: "tiao",
    tiao1: "aa",

    focus: false,


    obj: ""
  },
  //获取输入内容
  inputClick: function (e) {
    // console.log(e)
    var that = this
    var value = e.detail.value
    this.setData({
      value: value
    })
  },
  //隐藏展示
  hideClick: function () {
    var that = this
    var hide = that.data.hide
    var heights = that.data.heights
    if (hide == '') {
      hide = true
      heights = "680"
    } else {
      hide = ""
      heights = "860"
    }
    that.setData({
      hide: hide,
      heights: heights
    })
  },
  //发送
  faClick: function () {
    var that = this
    var value = that.data.value
    console.log(value)
    var obj = {}
    obj.id = that.data.id
    obj.himg = "/hyb_yl/images/header_0" + that.data.id + ".png"
    obj.con = value
    var chatArr = that.data.chatArr
    chatArr.push(obj)
    var value = ""
    var focus = true
    that.setData({
      chatArr: chatArr,
      value: value,
      focus: focus
    })
    that.bottom()
  },
  //点击底部按钮
  baoClick: function (e) {
    var that = this
    var img = e.currentTarget.dataset.img
    console.log(img)
    var title = e.currentTarget.dataset.title
    console.log(img, title)
    if (img == "/hyb_yl/images/baogao_01.png") {
      img = "/hyb_yl/images/baogao_02.png"
    } else if (img = "/hyb_yl/images/jiankangdangan_01.png") {
      img = "/hyb_yl/images/jiankangdangan_02.png"
    }
    var obj = {}
    obj.id = that.data.id
    obj.himg = "/hyb_yl/images/header_0" + that.data.id + ".png"
    obj.wen = [{
      title: title,
      con: "发了首付款紧身裤啦放假拉伸",
      time: "2018-03-15",
      img: img
    }]

    var chatArr = that.data.chatArr
    chatArr.push(obj)
    var value = ""
    that.setData({
      chatArr: chatArr,
      value: value
    })
    that.bottom()
  },
  //图片
  phoneClick: function () {
    var that = this
    wx.chooseImage({
      count: 9, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths)
        var obj = {}
        obj.id = that.data.id
        obj.himg = "../images/header_0" + that.data.id + ".png"
        obj.tu = tempFilePaths
        var chatArr = that.data.chatArr
        chatArr.push(obj)
        that.setData({
          chatArr: chatArr
        })
        that.bottom()
      }
    })

  },
  //获取图片宽高
  load: function (e) {
    var that = this
    console.log(e)
    var widths = e.detail.width
    that.setData({
      widths: widths,
    })
  },
  //预览
  previewImage: function (e) {
    var arr = e.currentTarget.dataset.arr
    var index = e.target.dataset.index
    console.log(index)
    var img = arr[index]
    console.log(arr, img)
    wx.previewImage({
      current: "", // 当前显示图片的http链接
      urls: arr // 需要预览的图片http链接列表
    })
  },
  //病情诊断
  zhenClick: function () {
    var overflow = 'hidden'
    var that = this
    var obj = that.data.obj
    console.log(obj)
    if (obj != "") {
      var jianshu = obj.jianshu
      var jieguo = obj.jieguo
      var chufang = obj.chufang
      that.setData({
        jianshu: jianshu,
        jieguo: jieguo,
        chufang: chufang,
      })
    }
    this.setData({
      overflow: overflow
    })
    that.bottom()
  },
  //隐藏
  hide1Click: function () {
    var overflow = ""
    this.setData({
      overflow: overflow
    })
  },
  //提交
  subClick: function (e) {
    console.log(e)
    var that = this
    var jianshu = e.detail.value.jianshu
    var jieguo = e.detail.value.jieguo
    var chufang = e.detail.value.chufang
    var overflow = ""
    if (jianshu == "") {
      wx.showToast({
        title: '请填写病情简述',
        icon: "none"
      })
    } else if (jieguo == "") {
      wx.showToast({
        title: '请填写诊断结果',
        icon: "none"
      })
    } else if (chufang == '') {
      wx.showToast({
        title: '请填写处方',
        icon: "none"
      })
    } else {
      var obj = e.detail.value
      var chatArr = that.data.chatArr
      var id = that.data.id
      var obj1 = {}
      obj1.id = id
      obj1.himg = "/hyb_yl/images/header_0" + id + ".png"
      obj1.wen = [{
        title: "诊断结果",
        con: jieguo,
        time: "2018-03-15",
        img: "/hyb_yl/images/baogao_02.png",
        btn: "zhenClick"
      }]
      chatArr.push(obj1)
      that.setData({
        obj: obj,
        chatArr: chatArr,
        overflow: overflow
      })
    }
  },
  //专家详情
  zhuanDetailClick: function () {
    wx.navigateTo({
      url: '/pages/zhuan-detail/zhuan-detail',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this
    var zid = options.zid
    var qid = options.qid
    var user_openid = options.user_openid
    var q_category = options.q_category
    var tiao1 = that.data.tiao1
    var fromuser = options.fromuser
    var z_name = options.z_name
    var z_zhiwu = options.z_zhiwu
    var z_thumbs = options.z_thumbs
    that.setData({
      tiao1: tiao1,
      zid: zid,
      user_openid: user_openid,
      q_category: q_category,
      qid: qid,
      fromuser: fromuser,
      z_name: z_name,
      z_zhiwu: z_zhiwu,
      z_thumbs: z_thumbs
    })
    that.bottom();
  },
  // 获取hei的id节点然后屏幕焦点调转到这个节点 
  bottom: function () {
    var that = this;
    var query = wx.createSelectorQuery()
    query.select('#hei').boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec(function (res) {
      that.setData({
        scrollTop: res[0].height
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getAllquestion()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getAllquestion: function () {
    var that = this
    var zid = that.data.zid
    var user_openid = that.data.user_openid
    var qid = that.data.qid
    var fromuser = that.data.fromuser
    app.util.request({
      'url': 'entry/wxapp/Allquestion',
      data: {
        qid: qid,
        zid: zid,
        user_openid: user_openid,
        fromuser: fromuser
      },
      success: function (res) {
        console.log(res)
        that.setData({
          qs: res.data.data
        })
      }
    })
  },
  zixun: function (e) {
    var that = this
    var id = that.data.zid
    var openid = that.data.user_openid
    var q_category = that.data.q_category
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?id=' + id + '&openid=' + openid + '&q_category=' + q_category,
    })
  }
})